using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Collections;
using System.Globalization;
using Sanford.Collections.Generic;

namespace RapidSpider
{
    public sealed class RegistryAgent
    {
        #region Constants
        #region Global Settings
        private const string KEY_ALWAYS_ON_TOP = "Always On Top";
        #endregion

        #region Downloading
        private const string KEY_BUFFER_SIZE = "Buffer Size";
        private const string KEY_CONCURRENT_DOWNLOADS = "Concurrent Downloads";
        private const string KEY_TIMEOUT = "Timeout";
        #endregion

        #region Directories
        private const string KEY_DOWNLOAD_PATH = "Download Path";
        private const string KEY_LOG_ACTIONS = "Log Actions";
        private const string KEY_LOG_FILE_PATH = "Log File Path";
        #endregion

        #region Rapidshare.com
        private const string KEY_RAPIDSHARECOM_LOGIN = "Login";
        private const string KEY_RAPIDSHARECOM_PASSWORD = "Password";
        private const string KEY_RAPIDSHARECOM_PREMIUM_ACCOUNT_EXPIRY = "Premium Account Expiry";
        private const string KEY_RAPIDSHARECOM_COGENT = "Cogent";
        private const string KEY_RAPIDSHARECOM_COGENT2 = "Cogent #2";
        private const string KEY_RAPIDSHARECOM_DEUTSCHETELEKOM = "Deutsche Telekom";
        private const string KEY_RAPIDSHARECOM_GLOBALCROSSING = "GlobalCrossing";
        private const string KEY_RAPIDSHARECOM_GLOBALCROSSING2 = "GlobalCrossing #2";
        private const string KEY_RAPIDSHARECOM_LEVEL3 = "Level(3)";
        private const string KEY_RAPIDSHARECOM_LEVEL32 = "Level(3) #2";
        private const string KEY_RAPIDSHARECOM_LEVEL33 = "Level(3) #3";
        private const string KEY_RAPIDSHARECOM_LEVEL34 = "Level(3) #4";
        private const string KEY_RAPIDSHARECOM_TELEGLOBE = "Teleglobe";
        private const string KEY_RAPIDSHARECOM_TELIASONERA = "TeliaSonera";
        private const string KEY_RAPIDSHARECOM_TELIASONERA2 = "TeliaSonera #2";
        #endregion

        #region Hotfile.com
        private const string KEY_HOTFILECOM_LOGIN = "Login";
        private const string KEY_HOTFILECOM_PASSWORD = "Password";
        #endregion

        private const string KEY_DOWNLOAD_HISTORY = "Download History";
        public const int DOWNLOAD_HISTORY_SIZE = 10;
        #endregion

        #region Members
        private static Deque<string> _DownloadHistory = new Deque<string>();
        #endregion

        #region Properties
        public static Deque<string> DownloadHistory
        {
            get { return RegistryAgent._DownloadHistory; }
        }

        public static RegistryKey SettingsKey
        {
            get
            {
                RegistryKey theSettingsKey =
                    Registry.LocalMachine.OpenSubKey("Software\\www.ne0ge0.com\\RapidSpider", true);
                if (null == theSettingsKey)
                {
                    RegistryKey theSoftwareKey =
                        Registry.LocalMachine.OpenSubKey("Software", true);
                    RegistryKey theComputaKey =
                        theSoftwareKey.CreateSubKey("www.ne0ge0.com");
                    theSettingsKey =
                        theComputaKey.CreateSubKey("RapidSpider");
                }
                return theSettingsKey;
            }
        }

        #region Global Settings
        public static bool AlwaysOnTop
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_ALWAYS_ON_TOP))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_ALWAYS_ON_TOP,
                        false);
                }
                return Convert.ToBoolean(
                    RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_ALWAYS_ON_TOP),
                    CultureInfo.CurrentCulture);

            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_ALWAYS_ON_TOP, value);
            }
        }
        #endregion

        #region Downloading
        public static int BufferSize
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_BUFFER_SIZE))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_BUFFER_SIZE,
                        8192);
                }
                return Convert.ToInt32(
                    RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_BUFFER_SIZE),
                    CultureInfo.CurrentCulture);

            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_BUFFER_SIZE, value);
            }
        }

        public static int ConcurrentDownloads
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_CONCURRENT_DOWNLOADS))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_CONCURRENT_DOWNLOADS,
                        3);
                }
                return Convert.ToInt32(
                    RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_CONCURRENT_DOWNLOADS),
                    CultureInfo.CurrentCulture);

            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_CONCURRENT_DOWNLOADS, value);
            }
        }

        public static int Timeout
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_TIMEOUT))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_TIMEOUT,
                        10);
                }
                return Convert.ToInt32(
                    RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_TIMEOUT),
                    CultureInfo.CurrentCulture);

            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_TIMEOUT, value);
            }
        }
        #endregion

        #region Directories
        public static string DownloadPath
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_DOWNLOAD_PATH))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_DOWNLOAD_PATH,
                        String.Empty);
                }
                return RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_DOWNLOAD_PATH).ToString();
            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_DOWNLOAD_PATH, value);
            }
        }

        public static bool LogActions
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_LOG_ACTIONS))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_LOG_ACTIONS,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_LOG_ACTIONS),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_LOG_ACTIONS, value);
            }
        }
        
        public static string LogFilePath
        {
            get
            {
                if (null == RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_LOG_FILE_PATH))
                {
                    RegistryAgent.SettingsKey.SetValue(
                        RegistryAgent.KEY_LOG_FILE_PATH,
                        Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                }
                return RegistryAgent.SettingsKey.GetValue(RegistryAgent.KEY_LOG_FILE_PATH).ToString();
            }
            set
            {
                RegistryAgent.SettingsKey.SetValue(RegistryAgent.KEY_LOG_FILE_PATH, value);
            }
        }
        #endregion

        #region Rapidshare.com
        public static RegistryKey RapidshareComKey
        {
            get
            {
                RegistryKey theRapidshareComKey =
                    Registry.LocalMachine.OpenSubKey("Software\\www.ne0ge0.com\\RapidSpider\\Rapidshare.com", true);
                if (null == theRapidshareComKey)
                {
                    RegistryKey theSoftwareKey =
                        Registry.LocalMachine.OpenSubKey("Software", true);
                    RegistryKey theComputaKey =
                        theSoftwareKey.CreateSubKey("www.ne0ge0.com");
                    RegistryKey theSettingsKey =
                        theComputaKey.CreateSubKey("RapidSpider");
                    theRapidshareComKey =
                        theSettingsKey.CreateSubKey("Rapidshare.com");
                }
                return theRapidshareComKey;
            }
        }

        public static string RapidshareComLogin
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LOGIN))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_LOGIN,
                        String.Empty);
                }
                return RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LOGIN).ToString();
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_LOGIN, value);
            }
        }
        
        public static string RapidshareComPassword
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_PASSWORD))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_PASSWORD,
                        String.Empty);
                }
                return RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_PASSWORD).ToString();
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_PASSWORD, value);
            }
        }

        public static string EscapedRapidsharePassword
        {
            get
            {
                StringBuilder theEscapedPassword = new StringBuilder();

                foreach (char thisChar in RegistryAgent.RapidshareComPassword.ToCharArray())
                {
                    theEscapedPassword.AppendFormat(
                        CultureInfo.CurrentCulture,
                        "%{0}",
                        ((int)thisChar).ToString(
                            "X",
                            CultureInfo.CurrentCulture));
                }

                return theEscapedPassword.ToString();
            }
        }
        
        public static string RapidshareComPremiumAccountExpiry
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_PREMIUM_ACCOUNT_EXPIRY))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_PREMIUM_ACCOUNT_EXPIRY,
                        String.Empty);
                }
                return RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_PREMIUM_ACCOUNT_EXPIRY).ToString();
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_PREMIUM_ACCOUNT_EXPIRY, value);
            }
        }

        public static bool RapidshareComCogent
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_COGENT,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT, value);
            }
        }

        public static bool RapidshareComCogent2
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT2))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_COGENT2,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT2),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_COGENT2, value);
            }
        }

        public static bool RapidshareComDeutscheTelekom
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_DEUTSCHETELEKOM))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_DEUTSCHETELEKOM,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_DEUTSCHETELEKOM),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_DEUTSCHETELEKOM, value);
            }
        }

        public static bool RapidshareComGlobalCrossing
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING, value);
            }
        }

        public static bool RapidshareComGlobalCrossing2
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING2))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING2,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING2),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_GLOBALCROSSING2, value);
            }
        }

        public static bool RapidshareComLevel3
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL3))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_LEVEL3,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL3),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL3, value);
            }
        }

        public static bool RapidshareComLevel32
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL32))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_LEVEL32,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL32),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL32, value);
            }
        }

        public static bool RapidshareComLevel33
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL33))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_LEVEL33,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL33),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL33, value);
            }
        }

        public static bool RapidshareComLevel34
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL34))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_LEVEL34,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL34),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_LEVEL34, value);
            }
        }

        public static bool RapidshareComTeleglobe
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELEGLOBE))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_TELEGLOBE,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELEGLOBE),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELEGLOBE, value);
            }
        }

        public static bool RapidshareComTeliaSonera
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA, value);
            }
        }

        public static bool RapidshareComTeliaSonera2
        {
            get
            {
                if (null == RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA2))
                {
                    RegistryAgent.RapidshareComKey.SetValue(
                        RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA2,
                        true);
                }
                return Convert.ToBoolean(
                    RegistryAgent.RapidshareComKey.GetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA2),
                    CultureInfo.CurrentCulture);
            }
            set
            {
                RegistryAgent.RapidshareComKey.SetValue(RegistryAgent.KEY_RAPIDSHARECOM_TELIASONERA2, value);
            }
        }
        #endregion

        #region Hotfile.com
        public static RegistryKey HotfileComKey
        {
            get
            {
                RegistryKey theHotfileComKey =
                    Registry.LocalMachine.OpenSubKey("Software\\www.ne0ge0.com\\RapidSpider\\Hotfile.com", true);
                if (null == theHotfileComKey)
                {
                    RegistryKey theSoftwareKey =
                        Registry.LocalMachine.OpenSubKey("Software", true);
                    RegistryKey theComputaKey =
                        theSoftwareKey.CreateSubKey("www.ne0ge0.com");
                    RegistryKey theSettingsKey =
                        theComputaKey.CreateSubKey("RapidSpider");
                    theHotfileComKey =
                        theSettingsKey.CreateSubKey("Hotfile.com");
                }
                return theHotfileComKey;
            }
        }

        public static string HotfileComLogin
        {
            get
            {
                if (null == RegistryAgent.HotfileComKey.GetValue(RegistryAgent.KEY_HOTFILECOM_LOGIN))
                {
                    RegistryAgent.HotfileComKey.SetValue(
                        RegistryAgent.KEY_HOTFILECOM_LOGIN,
                        String.Empty);
                }
                return RegistryAgent.HotfileComKey.GetValue(RegistryAgent.KEY_HOTFILECOM_LOGIN).ToString();
            }
            set
            {
                RegistryAgent.HotfileComKey.SetValue(RegistryAgent.KEY_HOTFILECOM_LOGIN, value);
            }
        }

        public static string HotfileComPassword
        {
            get
            {
                if (null == RegistryAgent.HotfileComKey.GetValue(RegistryAgent.KEY_HOTFILECOM_PASSWORD))
                {
                    RegistryAgent.HotfileComKey.SetValue(
                        RegistryAgent.KEY_HOTFILECOM_PASSWORD,
                        String.Empty);
                }
                return RegistryAgent.HotfileComKey.GetValue(RegistryAgent.KEY_HOTFILECOM_PASSWORD).ToString();
            }
            set
            {
                RegistryAgent.HotfileComKey.SetValue(RegistryAgent.KEY_HOTFILECOM_PASSWORD, value);
            }
        }
        #endregion
        #endregion

        #region Methods
        private RegistryAgent() {}

        public static void LoadDownloadHistory()
        {
            RegistryKey theDownloadHistoryKey =
                RegistryAgent.SettingsKey.OpenSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);

            if (null == theDownloadHistoryKey)
            {
                theDownloadHistoryKey =
                    RegistryAgent.SettingsKey.CreateSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);
            }

            RegistryAgent.DownloadHistory.Clear();

            foreach (string thisKeyName in
                theDownloadHistoryKey.GetValueNames())
            {
                RegistryAgent.DownloadHistory.PushFront(
                    theDownloadHistoryKey.GetValue(thisKeyName)
                        .ToString().Trim());
            }
        }

        public static void SaveDownloadHistory()
        {
            RegistryAgent.SettingsKey.DeleteSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);

            RegistryKey theDownloadHistoryKey =
                RegistryAgent.SettingsKey.CreateSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);

            Array theDownloadHistory = RegistryAgent.DownloadHistory.ToArray();

            for (int i = theDownloadHistory.Length - 1; i > -1; i--)
            {
                theDownloadHistoryKey.SetValue(
                    (i + 1).ToString(CultureInfo.CurrentCulture).PadLeft(2, '0'),
                    theDownloadHistory.GetValue(i)
                        .ToString().Trim());
            }
        }

        public static void ClearDownloadHistory()
        {
            RegistryAgent.SettingsKey.DeleteSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);
            RegistryAgent.SettingsKey.CreateSubKey(RegistryAgent.KEY_DOWNLOAD_HISTORY);

            RegistryAgent.DownloadHistory.Clear();
        }
        #endregion
    }
}
